/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package net.fonline.apps;

import javax.microedition.lcdui.Graphics;

/**
 *
 * @author Michael
 */
public class Missile {

    public Missile next;
    private int start_x = 0;
    private int start_y = 0;
    private int end_x = 0;
    private int end_y = 0;
    private int missile_type = 0;
    private int despawntime = 0;
    private double lifetime = 0;
    private EchoCanvas ec = null;

    public Missile(int start_x, int start_y, int end_x, int end_y, int missile_type, int despawntime) {
        this.start_x = start_x;
        this.start_y = start_y;
        this.end_x = end_x;
        this.end_y = end_y;
        this.missile_type = missile_type;
        this.despawntime = despawntime;
    }

    public void update(Graphics g) {
        ec = LineTowerWars.ec;
        if (missile_type != 0) {
            g.setColor(255, 0, 0);
        } else {
            g.setColor(0, 0, 255);
        }
        g.drawLine((int) ((this.start_x + 9) * this.ec.scale) + this.ec.relX, (int) ((this.start_y + 9) * this.ec.scale) + this.ec.relY, (int) ((this.end_x + 5) * this.ec.scale) + this.ec.relX, (int) ((this.end_y + 5) * this.ec.scale) + this.ec.relY);
    }

    void move(double time) {
        lifetime += time;
        if (lifetime > despawntime) {
            LineTowerWars.ec.missiles.remove(this);
        }
    }
}
